#include "StdAfx.h"

#include "Physical Gpu.h"

using namespace StillDesign::NvApi;

PhysicalGpu::PhysicalGpu( NvPhysicalGpuHandle physicalGpu )
{
	_physicalGpu = physicalGpu;
}

//GpuThermalSettings^ PhysicalGpu::GetThermalSettings()
//{
//	return GpuThermalSettings( 
//	ThermalTarget::All );
//}
GpuThermalSettings^ PhysicalGpu::GetThermalSettings( ThermalTarget sensorIndex )
{
	NV_GPU_THERMAL_SETTINGS settings = {0};
	settings.version = NV_GPU_THERMAL_SETTINGS_VER;
	settings.count = 0;
	
	settings.sensor[ 0 ].controller = NVAPI_THERMAL_CONTROLLER_UNKNOWN;
	settings.sensor[ 0 ].target = NVAPI_THERMAL_TARGET_GPU;
	
	settings.sensor[ 1 ].controller = NVAPI_THERMAL_CONTROLLER_UNKNOWN;
	settings.sensor[ 1 ].target = NVAPI_THERMAL_TARGET_GPU;
	
	settings.sensor[ 2 ].controller = NVAPI_THERMAL_CONTROLLER_UNKNOWN;
	settings.sensor[ 2 ].target = NVAPI_THERMAL_TARGET_GPU;
	
	int result = NvAPI_GPU_GetThermalSettings( this->Handle, (int)sensorIndex, &settings );
	
	ThrowOnError( result );
	
	return gcnew GpuThermalSettings( settings );
}

int PhysicalGpu::AllOutputs::get()
{
	NvU32 outputsMask;
	int result = NvAPI_GPU_GetAllOutputs( this->Handle, &outputsMask );
	
	ThrowOnError( result );
	
	return outputsMask;
}
int PhysicalGpu::ConnectedOutputs::get()
{
	NvU32 connectedOutputs;
	int result = NvAPI_GPU_GetConnectedOutputs( this->Handle, &connectedOutputs );
	
	ThrowOnError( result );
	
	return connectedOutputs;
}
int PhysicalGpu::ConnectedSliOutputs::get()
{
	NvU32 connectedOutputs;
	int result = NvAPI_GPU_GetConnectedSLIOutputs( this->Handle, &connectedOutputs );
	
	ThrowOnError( result );
	
	return connectedOutputs;
}
int PhysicalGpu::ConnectedOutputsWithLidState::get()
{
	NvU32 connectedOutputs;
	int result = NvAPI_GPU_GetConnectedOutputsWithLidState( this->Handle, &connectedOutputs );
	
	ThrowOnError( result );
	
	return connectedOutputs;
}
int PhysicalGpu::ConnectedSliOutputsWithLidState::get()
{
	NvU32 connectedOutputs;
	int result = NvAPI_GPU_GetConnectedSLIOutputsWithLidState( this->Handle, &connectedOutputs );
	
	ThrowOnError( result );
	
	return connectedOutputs;
}
SystemType PhysicalGpu::SystemType::get()
{
	NV_SYSTEM_TYPE type;
	int result = NvAPI_GPU_GetSystemType( this->Handle, &type );
	
	ThrowOnError( result );
	
	return (StillDesign::NvApi::SystemType)type;
}
int PhysicalGpu::ActiveOutputs::get()
{
	NvU32 activeOutputs;
	int result = NvAPI_GPU_GetActiveOutputs( this->Handle, &activeOutputs );
	
	ThrowOnError( result );
	
	return activeOutputs;
}
String^ PhysicalGpu::FullName::get()
{
	NvAPI_ShortString name;
	int result = NvAPI_GPU_GetFullName( this->Handle, name );
	
	ThrowOnError( result );
	
	return Functions::UnmanagedToManagedString( &name[ 0 ] );
}
StillDesign::NvApi::GpuType PhysicalGpu::GpuType::get()
{
	NV_GPU_TYPE type;
	int result = NvAPI_GPU_GetGPUType( this->Handle, &type );
	
	ThrowOnError( result );
	
	return (StillDesign::NvApi::GpuType)type;
}
GpuBusType PhysicalGpu::BusType::get()
{
	NV_GPU_BUS_TYPE type;
	int result = NvAPI_GPU_GetBusType( this->Handle, &type );
	
	ThrowOnError( result );
	
	return (GpuBusType)type;
}
int PhysicalGpu::BusId::get()
{
	NvU32 id;
	int result = NvAPI_GPU_GetBusId( this->Handle, &id );
	
	ThrowOnError( result );
	
	return id;
}
int PhysicalGpu::BusSlotId::get()
{
	NvU32 id;
	int result = NvAPI_GPU_GetBusSlotId( this->Handle, &id );
	
	ThrowOnError( result );
	
	return id;
}
int PhysicalGpu::IRQ::get()
{
	NvU32 irq;
	int result = NvAPI_GPU_GetIRQ( this->Handle, &irq );
	
	ThrowOnError( result );
	
	return irq;
}
int PhysicalGpu::VBiosRevision::get()
{
	NvU32 rev;
	int result = NvAPI_GPU_GetVbiosRevision( this->Handle, &rev );
	
	ThrowOnError( result );
	
	return rev;
}
int PhysicalGpu::VBiosOemRevision::get()
{
	NvU32 rev;
	int result = NvAPI_GPU_GetVbiosOEMRevision( this->Handle, &rev );
	
	ThrowOnError( result );
	
	return rev;
}
String^ PhysicalGpu::VBiosVersionString::get()
{
	NvAPI_ShortString version;
	int result = NvAPI_GPU_GetVbiosVersionString( this->Handle, version );
	
	ThrowOnError( result );
	
	return Functions::UnmanagedToManagedString( &version[ 0 ] );
}
int PhysicalGpu::AgpAperture::get()
{
	NvU32 agpAperture;
	int result = NvAPI_GPU_GetAGPAperture( this->Handle, &agpAperture );
	
	ThrowOnError( result );
	
	return agpAperture;
}
int PhysicalGpu::CurrentAgpRate::get()
{
	NvU32 agpRate;
	int result = NvAPI_GPU_GetCurrentAGPRate( this->Handle, &agpRate );
	
	ThrowOnError( result );
	
	return agpRate;
}
int PhysicalGpu::CurrentPcieDownstreamWidth::get()
{
	NvU32 w;
	int result = NvAPI_GPU_GetCurrentPCIEDownstreamWidth( this->Handle, &w );
	
	ThrowOnError( result );
	
	return w;
}
int PhysicalGpu::PhysicalFrameBufferSize::get()
{
	NvU32 s;
	int result = NvAPI_GPU_GetPhysicalFrameBufferSize( this->Handle, &s );
	
	ThrowOnError( result );
	
	return s;
}
int PhysicalGpu::VirtualFrameBufferSize::get()
{
	NvU32 s;
	int result = NvAPI_GPU_GetVirtualFrameBufferSize( this->Handle, &s );
	
	ThrowOnError( result );
	
	return s;
}

NvPhysicalGpuHandle PhysicalGpu::Handle::get()
{
	return _physicalGpu;
}